import { isEmpty, validPhone } from "@/utils/validate";

// 必须填
export const validatePhone = (rule: any, value: any, callback: any) => {
  if (value === "") {
    callback(new Error("请输入手机号"));
  } else if (!validPhone(value)) {
    callback(new Error("请输入正确的手机号"));
  } else {
    callback();
  }
};
// 如果填了 就一定要正确
export const validatePhoneEmpty = (rule: any, value: any, callback: any) => {
  if (!isEmpty(value) && !validPhone(value)) {
    callback(new Error("请输入正确的手机号"));
  } else {
    callback();
  }
};

interface validatePasswordFace extends Record<string, any> {
  rule: any;
  value: any;
  callback: any;
  type: string;
}

// 修改不要密码
export const validatePassword = ({
  rule,
  value,
  callback,
  type,
}: validatePasswordFace) => {
  console.log(value, type);
  if (type == "create" && isEmpty(value)) {
    callback(new Error("请输入密码"));
  } else {
    callback();
  }
};

export const validateNewPassword = (
  rule: any,
  value: string,
  callback: any
) => {
  console.log(value);
  if (
    !/^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+-={}\[\]\\|:;"',./<>?~]).{10,20}$/.test(
      value
    )
  ) {
    callback(new Error("密码必须包含大小写字母、数字、特殊符号，长度10-20位"));
  } else {
    callback();
  }
};
